package com.learn.mybatis.springboot.controller;

import com.learn.mybatis.springboot.domain.User;
import com.learn.mybatis.springboot.service.UserService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
/**
 * 控制器
 * @author cong zhi
 * @email  448341911@qq.com
 * @createDate   2023/2/24 15:27
 * @version: v1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/add")
    public String hello(@RequestBody User user) {

        boolean result = userService.save(user);
        if (result) {
            return "添加成功！";
        } else {
            return "添加失败!";
        }
    }

    @GetMapping("/del/{id}")
    public String del(@PathVariable("id") Integer id) {

        boolean result = userService.removeById(id);
        if (result) {
            return "删除成功！";
        } else {
            return "删除失败!";
        }
    }

    @GetMapping("/load/{id}")
    public User load(@PathVariable("id") Integer id) {

        return userService.getById(id);
    }

    @Resource
    private RestTemplate restTemplate;

}
